package com.jr.util;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * @Function：MD5加密工具类
 * @Author 梁明哲
 * @Email 424577090@qq.com
 * @Package com.jr.service.impl
 * @Project InvoiceManage
 * @Date 2023-02-20 09:11:08
 */
public class MD5Util {

    // 加盐
    public static String getSalt() {
        String words = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()~";
        StringBuilder strb = new StringBuilder();
        for (int i = 0; i < 8; i++) {
            strb.append(words.charAt((int)Math.floor(Math.random() * words.length())));
        }
        return strb.toString();
    }

    public static String stringToMD5(String str) {
        return DigestUtils.md5Hex(str);
    }
}
